package com.midea.thread;

public class TestSynchronized6 implements Runnable {
    static TestSynchronized6 instance=new TestSynchronized6();
    static int i=0;
    @Override
    public void run() {
        synchronized(this){
            for(int j=0;j<10000;j++){
                i++;
                System.out.println(j);
            }
        }

       /* //class对象锁
        synchronized(Main.class){
            for(int j=0;j<1000000;j++){
                i++;
            }
        }*/
    }



    public static void main(String[] args) throws InterruptedException {
        Thread t1=new Thread(instance);
        Thread t2=new Thread(instance);
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(i);
    }
}
